package com.crack.simpleapiclientsdk.utils;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.Map;

/**
 * @version 1.0
 * @Description
 * @CreateTime 2023/3/20 0:13
 */

public class StringUtils {
    public static String formatJsonStrToGetParams(String json){
//        String json = "{\"user\":\"crack\",\"age\":\"15\"}";
        JSONObject entries = JSONUtil.parseObj(json);
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Object> stringObjectEntry : entries.entrySet()) {
            sb.append(stringObjectEntry.getKey() + "=" + stringObjectEntry.getValue() + "&");
        }
        sb.deleteCharAt(sb.length()-1);
        sb.insert(0,"?");
        return sb.toString();
    }
}
